<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache" content="no-cache">
<title>Student Search</title>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath }/static/css/myPage.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/myPage.js"></script>
<style type="text/css">
	ul, ol, li {
		list-style: none;
	}
</style>
<script type="text/javascript">
$(function(){
	//	学生搜索页面
	$("#specialty").change(function(){
		var specialtyId = $(this).val()
		if(specialtyId == 0){
			$("#grade").html("<option value='0'>班级选择</option>")
		}
		if(specialtyId != 0){
			$.get(
					"${pageContext.request.contextPath}/spe_ajaxSpecialty",
					{"specialtyId":specialtyId},
					function(data){
						html = ""
						if(data.grades.length == 0){
							html += "<option value='0'>空</option>"
						}
						
						for(var i = 0;i<data.grades.length;i++){
							html += "<option value='"+data.grades[i].id+"'>"+data.grades[i].name+"</option>"
						}
						$("#grade").html(html)
						
					},
					"json"
			);
		}
	})
	
	// 学生列表显示，生日内容截取前10显示
	$(".brith").each(function(){
		text = $(this).html()
		$(this).html(text.slice(0,10))
	})
})

</script>
</head>
<body>
	<div class="conten">
		<div class="search_top" style="height:80px; line-height: 80px;">
			<form action="stu_search" autocomplete="off">
				<span style="margin-right: 20px;">
					专业班级查找：
					<select name="specialtyId" id="specialty">
						<option value="0">专业选择</option>
						<c:forEach items="${specialtys }" var="specialty"> 
							<option value="${specialty.specialtyId }">${specialty.specialtyName }</option>
						</c:forEach>
					</select>
					<select name="gradeId" id="grade">
						<option value="0">班级选择</option>
					</select>
				</span>
				<span style="margin-right: 20px;">
					学生姓名：<input type="text" name="studentName"/>
				</span>
				<span>
					学生学号：<input type="text" name="studentId"/>
				</span>
				<input type="submit" value="查询"/>
			</form>
		</div>
		<hr width=100%>
		<div class="search_data">
			<!-- 搜索数据显示 -->
			<c:if test="${not empty searchStudents}">
				<table border="1" style="border-collapse:collapse;width:100%;">
				<tr>
					<td>学号</td>
					<td>姓名</td>
					<td>性别</td>
					<td>电话</td>
					<td>生日</td>
					<td>地址</td>
					<td>专业</td>
					<td>班级</td>
				</tr>
				<c:forEach items="${searchStudents }" var="student">
					<tr>
						<td>${student.id }</td>
						<td>${student.name }</td>
						<td>
						<c:if test="${student.sex eq 0}">
							女
						</c:if>
						<c:if test="${student.sex eq 1}">
							男
						</c:if>
						</td>
						<td>${student.phone }</td>
						<td class="brith">${student.brith }</td>
						<td>${student.address }</td>
						<td>${student.grade.specialty.specialtyName }</td>
						<td>${student.grade.name }</td>
					</tr>
				</c:forEach>
			</table>
			</c:if>
		</div>
	</div>
	
	<!-- 分页 -->
	<div style="position:absolute;bottom:150px;right:20px;">
		<c:if test="${pageCount ne 0}">
			<jsp:include page="myPage.jsp"></jsp:include>
		</c:if>
	</div>
	
</body>
</html>